package a0.annotation;

import java.lang.annotation.Annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
import java.util.ArrayList;
import java.util.List;

/**
 * author: xiaoxu
 * 组装对象应用（数据库连接池）
 **/
//@SuppressWarnings("all")//消除警告
public class Test {
    public static void main(String[] args) {
        List list = new ArrayList();
        list.add("1");
        list.add(1);


        Class<Cat> catClass = Cat.class;
        //获取类上应用的指定注解
        MyAnnotation annotation = catClass.getAnnotation(MyAnnotation.class);
        //获取注解上变量的值
        String name = annotation.name();
        int age = annotation.age();
        Color color = annotation.color();
        String[] like = annotation.like();

        try {
            Cat cat = catClass.newInstance();
            cat.setAge(age);
            cat.setName(name);
            cat.setColor(color);
            cat.setLike(like);
            System.out.println(cat.toString());
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }


    }
}
